package divTreat;

import java.util.Random;

public class sortArray {
    public int[] sortArray(int[] nums) {
        int l=0;
        int n=nums.length-1;
        qsort(nums,l,n);
        return nums;
    }
    public void swap(int nums[],int i,int j){
        int n=nums[i];
        nums[i]=nums[j];
        nums[j]=n;
    }
    public void qsort(int nums[],int l,int r){
        if(l>=r) return;
        int left=l-1;
        int right=r+1;
        int i=l;
        int key = nums[new Random().nextInt(r - l + 1) + l];
        while(i<right){
            if(nums[i]<key){
                swap(nums,++left,i++);
            }else if(nums[i]==key){
                i++;
            }else{
                swap(nums,--right,i);
            }
        }
        qsort(nums,l,left);
        qsort(nums,right,r);
    }
}
